package cc.realxyq.demo.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author kwhan
 * @date 2022年01月10日 12:51
 */
@Slf4j
@Aspect
public class LogAspect {

    @SuppressWarnings("all")
    @Pointcut("execution(* cc.realxyq.demo.aop.Calculator.*(..))")
    public void pointcut(){}

    @Before("pointcut()")
    public void logBefore(){
        log.info("我是@Before，");
    }
    @After("pointcut()")
    public void logAfter(){
        log.info("我是@After，");
    }
    @AfterReturning("pointcut()")
    public void logAfterReturning(){
        log.info("我是返回通知：");
    }

    @AfterThrowing("pointcut()")
    public void logAfterThrowing(){
        log.error("我是异常通知：");
    }

    @Around("pointcut()")
    public Object logAround(ProceedingJoinPoint pjp) {

        Object proceed = null;
        try {
            log.warn("我是Around通知：before.....");
            proceed = pjp.proceed();
            log.warn("我是Around通知：after return ....");
        } catch (Throwable e) {
            log.warn("我是Around通知：发生异常了。。。。");
        } finally {
            log.warn("我是Around通知：After.....");
        }
        return proceed;
    }

}
